﻿using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Windows.Media.Imaging;
using UT3Bots;

using UT3Bots.UTItems;
using UT3Bots.Communications;


namespace UT3Bots.Visualizer.Controls
{
	public partial class UTUIItemPoint : UserControl
    {
        private const string ICON_WTF_URL = "/Assets/MapIcons/WTF.png";

        private const string ICON_HEALTH_VIAL_URL = "/Assets/MapIcons/Health/Vial.png";
        private const string ICON_HEALTH_MED_URL = "/Assets/MapIcons/Health/Med.png";
        private const string ICON_HEALTH_BIG_URL = "/Assets/MapIcons/Health/Big.png";
		private const string ICON_HEALTH_SUPER_URL = "/Assets/MapIcons/Health/Super.png";

        private const string ICON_ARMOR_BESERK_URL = "/Assets/MapIcons/Armor/Beserk.png";
        private const string ICON_ARMOR_CHEST_URL = "/Assets/MapIcons/Armor/Chest.png";
        private const string ICON_ARMOR_HELMET_URL = "/Assets/MapIcons/Armor/Helmet.png";
        private const string ICON_ARMOR_INVIS_URL = "/Assets/MapIcons/Armor/Invis.png";
        private const string ICON_ARMOR_INVUL_URL = "/Assets/MapIcons/Armor/Invul.png";
        private const string ICON_ARMOR_JUMP_BOOTS_URL = "/Assets/MapIcons/Armor/JumpBoots.png";
        private const string ICON_ARMOR_SHIELD_BELT_URL = "/Assets/MapIcons/Armor/ShieldBelt.png";
        private const string ICON_ARMOR_THIGH_PADS_URL = "/Assets/MapIcons/Armor/ThighPads.png";
        private const string ICON_ARMOR_U_DAMAGE_URL = "/Assets/MapIcons/Armor/UDamage.png";

        private const string ICON_WEAPON_AVRIL_URL = "/Assets/MapIcons/Weapon/Avril.png";
        private const string ICON_WEAPON_BIO_RIFLE_URL = "/Assets/MapIcons/Weapon/BioRifle.png";
        private const string ICON_WEAPON_ENFORCER_URL = "/Assets/MapIcons/Weapon/Enforcer.png";
        private const string ICON_WEAPON_FLAK_CANNON_URL = "/Assets/MapIcons/Weapon/FlakCannon.png";
        private const string ICON_WEAPON_IMPACT_HAMMER_URL = "/Assets/MapIcons/Weapon/ImpactHammer.png";
        private const string ICON_WEAPON_INSTAGIB_RIFLE_URL = "/Assets/MapIcons/Weapon/InstagibRifle.png";
        private const string ICON_WEAPON_LINK_GUN_URL = "/Assets/MapIcons/Weapon/LinkGun.png";
        private const string ICON_WEAPON_REDEEMER_URL = "/Assets/MapIcons/Weapon/Redeemer.png";
        private const string ICON_WEAPON_ROCKET_LAUNCHER_URL = "/Assets/MapIcons/Weapon/RocketLauncher.png";
        private const string ICON_WEAPON_SHOCK_RIFLE_URL = "/Assets/MapIcons/Weapon/ShockRifle.png";
        private const string ICON_WEAPON_SNIPER_RIFLE_URL = "/Assets/MapIcons/Weapon/SniperRifle.png";
        private const string ICON_WEAPON_STINGER_URL = "/Assets/MapIcons/Weapon/Stinger.png";
        private const string ICON_WEAPON_TRANSLOCATOR_URL = "/Assets/MapIcons/Weapon/Translocator.png";

        private const string ICON_AMMO_AVRIL_URL = "/Assets/MapIcons/Ammo/Avril.png";
        private const string ICON_AMMO_BIO_RIFLE_URL = "/Assets/MapIcons/Ammo/BioRifle.png";
        private const string ICON_AMMO_ENFORCER_URL = "/Assets/MapIcons/Ammo/Enforcer.png";
        private const string ICON_AMMO_FLACK_CANNON_URL = "/Assets/MapIcons/Ammo/FlakCannon.png";
        private const string ICON_AMMO_LINK_GUN_URL = "/Assets/MapIcons/Ammo/LinkGun.png";
        private const string ICON_AMMO_ROCKET_LAUNCHER_URL = "/Assets/MapIcons/Ammo/RocketLauncher.png";
        private const string ICON_AMMO_SHOCK_RIFLE_URL = "/Assets/MapIcons/Ammo/ShockRifle.png";
        private const string ICON_AMMO_SNIPER_RIFLE_URL = "/Assets/MapIcons/Ammo/SniperRifle.png";
        private const string ICON_AMMO_STINGER_URL = "/Assets/MapIcons/Ammo/Stinger.png";

        private UTItemPoint _itemPoint;
        private Tooltip _tooltip;

		#region Properties
		public UTItemPoint ItemPoint
		{
			get { return this._itemPoint; }
		}
		#endregion

		public UTUIItemPoint(UTItemPoint itemPoint)
		{
			this._itemPoint = itemPoint;
			this.DataContext = this._itemPoint;
			InitializeComponent();

            

            switch (_itemPoint.Item.ItemType)
            {
                case ItemType.Ammo:
                    switch ((AmmoType)_itemPoint.Item.ActualClass)
                    {
                        case AmmoType.Avril:
                            setImageAndCenter(ICON_AMMO_AVRIL_URL);
                            break;

                        case AmmoType.BioRifle:
                            setImageAndCenter(ICON_AMMO_BIO_RIFLE_URL);
                            break;

                        case AmmoType.Enforcer:
                            setImageAndCenter(ICON_AMMO_ENFORCER_URL);
                            break;

                        case AmmoType.FlakCannon:
                            setImageAndCenter(ICON_AMMO_FLACK_CANNON_URL);
                            break;

                        case AmmoType.LinkGun:
                            setImageAndCenter(ICON_AMMO_LINK_GUN_URL);
                            break;

                        case AmmoType.RocketLauncher:
                            setImageAndCenter(ICON_AMMO_ROCKET_LAUNCHER_URL);
                            break;

                        case AmmoType.ShockRifle:
                            setImageAndCenter(ICON_AMMO_SHOCK_RIFLE_URL);
                            break;

                        case AmmoType.SniperRifle:
                            setImageAndCenter(ICON_AMMO_SNIPER_RIFLE_URL);
                            break;

                        case AmmoType.Stinger:
                            setImageAndCenter(ICON_AMMO_STINGER_URL);
                            break;

						default:
                            setImageAndCenter(ICON_WTF_URL);
                            break;
                    }
                    break;

                case ItemType.Armor:
                    switch ((ArmorType)_itemPoint.Item.ActualClass)
                    {
                        case ArmorType.Berserk:
                            setImageAndCenter(ICON_ARMOR_BESERK_URL);
                            break;

                        case ArmorType.ChestArmour:
                            setImageAndCenter(ICON_ARMOR_CHEST_URL);
                            break;

                        case ArmorType.Helmet:
                            setImageAndCenter(ICON_ARMOR_HELMET_URL);
                            break;

                        case ArmorType.Invisibility:
                            setImageAndCenter(ICON_ARMOR_INVIS_URL);
                            break;

                        case ArmorType.Invulnerability:
                            setImageAndCenter(ICON_ARMOR_INVUL_URL);
                            break;

                        case ArmorType.JumpBoots:
                            setImageAndCenter(ICON_ARMOR_JUMP_BOOTS_URL);
                            break;

                        case ArmorType.ShieldBelt:
                            setImageAndCenter(ICON_ARMOR_SHIELD_BELT_URL);
                            break;

                        case ArmorType.ThighPads:
                            setImageAndCenter(ICON_ARMOR_THIGH_PADS_URL);
                            break;

                        case ArmorType.MultiplyDamage:
                            setImageAndCenter(ICON_ARMOR_U_DAMAGE_URL);
                            break;

						default:
                            setImageAndCenter(ICON_WTF_URL);
                            break;
                    }

                    break;

                case ItemType.Health:
                    switch ((HealthType)_itemPoint.Item.ActualClass)
                    {
                        case HealthType.HealthVial:
                            setImageAndCenter(ICON_HEALTH_VIAL_URL);
                            break;

                        case HealthType.MediBox:
                            setImageAndCenter(ICON_HEALTH_MED_URL);
                            break;

                        case HealthType.BigKegOHealth:
                            setImageAndCenter(ICON_HEALTH_BIG_URL);
                            break;

						case HealthType.SuperHealth:
							setImageAndCenter(ICON_HEALTH_SUPER_URL);
							break;

						default:
                            setImageAndCenter(ICON_WTF_URL);
                            break;
                    }
                    break;

                case ItemType.Weapon:
                    switch ((WeaponType)_itemPoint.Item.ActualClass)
                    {
                        case WeaponType.Avril:
                            setImageAndCenter(ICON_WEAPON_AVRIL_URL);
                            break;

                        case WeaponType.BioRifle:
                            setImageAndCenter(ICON_WEAPON_BIO_RIFLE_URL);
                            break;

                        case WeaponType.Enforcer:
                            setImageAndCenter(ICON_WEAPON_ENFORCER_URL);
                            break;

                        case WeaponType.FlakCannon:
                            setImageAndCenter(ICON_WEAPON_FLAK_CANNON_URL);
                            break;

                        case WeaponType.ImpactHammer:
                            setImageAndCenter(ICON_WEAPON_IMPACT_HAMMER_URL);
                            break;

                        case WeaponType.InstaGibRifle:
                            setImageAndCenter(ICON_WEAPON_INSTAGIB_RIFLE_URL);
                            break;

                        case WeaponType.LinkGun:
                            setImageAndCenter(ICON_WEAPON_LINK_GUN_URL);
                            break;

                        case WeaponType.Redeemer:
                            setImageAndCenter(ICON_WEAPON_REDEEMER_URL);
                            break;

                        case WeaponType.ShockRifle:
                            setImageAndCenter(ICON_WEAPON_SHOCK_RIFLE_URL);
                            break;

						case WeaponType.RocketLauncher:
							setImageAndCenter(ICON_WEAPON_ROCKET_LAUNCHER_URL);
							break;

                        case WeaponType.SniperRifle:
                            setImageAndCenter(ICON_WEAPON_SNIPER_RIFLE_URL);
                            break;

                        case WeaponType.Stinger:
                            setImageAndCenter(ICON_WEAPON_STINGER_URL);
                            break;

                        case WeaponType.Translocator:
                            setImageAndCenter(ICON_WEAPON_TRANSLOCATOR_URL);
                            break;

                        default:
                            setImageAndCenter(ICON_WTF_URL);
                            break;
                    }
                    break;

				default:
                    setImageAndCenter(ICON_WTF_URL);
                    break;
            }

		}

        private void setImageAndCenter(string imgUrl)
        {
            BitmapImage bmi = new BitmapImage(new Uri(imgUrl, UriKind.Relative));
            imgItem.Source = bmi;

			if (this._itemPoint.Item.ItemType == ItemType.Weapon)
			{
				Canvas.SetLeft(cvsItem, -40);
				imgItem.Width = 80;
				ellipseItem.Width = 80;
			}
        }


        private void UserControl_MouseEnter(object sender, MouseEventArgs e)
        {
            _tooltip = new Tooltip(_itemPoint.Item.ToString(), _itemPoint.Id.ToString(), _itemPoint.Location, e.GetPosition(null).X + 5 , e.GetPosition(null).Y + 5, 1);
            UTUIMap.CurrentMap.AddTooltip(_tooltip);
        }

        private void UserControl_MouseLeave(object sender, MouseEventArgs e)
        {
            UTUIMap.CurrentMap.RemoveTooltop(_tooltip);
            _tooltip = null;
        }

	}
}